<?php

abstract class JImageDB
{
    const BASE_PATH = '/classico/public/image_db/';
    const DEFAULT_IMAGE = 'noimg.png';

    /**
     * @param string $baseName
     * @param string $defaultImage
     * @return string
     */
    public static function getImageURL($baseName, $defaultImage = null)
    {
        if (!empty($baseName)) {
            if (file_exists(PATH_IMAGE_DB . "$baseName")) {
                return self::BASE_PATH . "$baseName";
            }
        }

        if (isset($defaultImage)) {
            if (file_exists(PATH_IMAGE_DB . "$defaultImage")) {
                return self::BASE_PATH . "$defaultImage";
            }
        }

        return self::BASE_PATH . self::DEFAULT_IMAGE;
    }
}
